import {Injectable} from "@angular/core";
import { HttpClient,HttpParams } from '@angular/common/http';

@Injectable()
export class RollService {
  serveUrl='https://clientaccountserver.lessonplan.cn'; /*学生用户API地址*/
  classServeurl='https://rosterserver.lessonplan.cn'; /*花名册API地址*/
  userServeUrl = 'https://accountserver.lessonplan.cn';/*教师用户API地址*/
  constructor(
    private http: HttpClient,
  ) { }
  /*根据学生的guid获取学生加入的班级的Guid*/
 getJoinClass (stuGuid):Promise<any> {
     return this.http.get(this.serveUrl+'/user/joined/'+stuGuid).toPromise().then(res=>{
        return res;
    })
 }
  /*根据班级Guid列表查询所有的班级*/
 getClassList(classGuidList):Promise<any> {
   return this.http.get(this.classServeurl+'/class/private',{
     params: new HttpParams().set('classListString',classGuidList)}).toPromise().then(res=>{
       return res;
   })
 }
  /*对输入关键字进行查询*/
 getSearchClassList(searchText:string,stuGuid:string):Promise<any>{
     return this.http.get(this.classServeurl+'/class/search',{
       params: new HttpParams().set('searchText',searchText).set('FK_UserGuid',stuGuid)}).toPromise().then(res=>{
         return res;
     })
 }
  /*加入班级*/
 joinClass(data:object):Promise<any>{
   return this.http.post(this.classServeurl+'/class/join2',data).toPromise().then(res=>{
     return res ;
   })
 }
  /*根据班级guid获取公告列表*/
 getClassNoticeList(classGuid):Promise<any>{
   return this.http.get(this.classServeurl+'/notice',{
     params: new HttpParams().set('class',classGuid)}).toPromise().then(res=>{
       return res;
   })
 }
  /*根据班级guid获取学生列表*/
 getStudentList(classGuid):Promise<any>{
   return this.http.get(this.serveUrl+'/user/studentlist/'+classGuid).toPromise().then(res=>{
     return res;
   })
 }
  /*根据用户Guid获取用户详细信息*/
  getUserInfo(userGuid:string):Promise<any>{
    return this.http.get(this.serveUrl+'/user/usermsg/'+userGuid).toPromise().then(res=>{
      return res ;
    })
  }
  /*根据班级guid和学生guid获取通知列表,state:0正常通知，99被删除的通知*/
  getNoticeList(classGuid,stuGuid):Promise<any>{
    return this.http.get(this.classServeurl+'/notice/getNoticeByUser',{
      params:new HttpParams().set('FK_ClassGuid',classGuid).set('FK_UserGuid',stuGuid)
    }).toPromise().then(res=>{
      return res;
    })
  }
  /*根据班级GUID和学生GUID获取学生成绩 扫码成绩*/
  getScoreOfStudent(classGuid,stuGuid):Promise<any>{
    let data = {
      studentGuid:stuGuid,
      classGuid:classGuid
    };
    return this.http.post('http://qrcodeserver.lessonplan.cn/score/detail',data).toPromise().then(res=>{
       return res;
    })
  }
/*根据班级Guid获取成绩计算模型*/
getScoreCountModle(classGuid):Promise<any>{
  return this.http.get(this.classServeurl+'/scoresegment/list/'+classGuid).toPromise().then(res=>{
     return res;
  })
}
/*获取作业墙的成绩*/
getScoreOfHomework(classGuid,stuGuid):Promise<any>{
  return this.http.get('http://homeworkserver.lessonplan.cn/teamMember/userScoreByClass',{
    params:new HttpParams().set('UserGuid',stuGuid).set('FK_ClassGuid',classGuid)
  }).toPromise().then(res=>{
    return res;
  })
}
/*修改用户基本信息*/
  updateUserInfo(userGuid,data):Promise<any>{
     return this.http.put(this.serveUrl+'/user/info?userGuid='+userGuid,data).toPromise().then(res=>{
       return res;
     })
  }
  /*修改用户头像*/
  updateHearImg(data):Promise<any>{
    return this.http.put(this.serveUrl+'/user/info/heardPhoto',data).toPromise().then(res=>{
       return res;
    })
  }
  /*删除用户头像*/
  deleteIMG(url:string):Promise<any>{
    return this.http.delete('http://upload.lessonplan.cn/clear?imgUrl='+url).toPromise().then(res=>{
      return res;
    })
  }
  //获取密保问题列表
  getProblemList():Promise<any>{
    return this.http.get(this.serveUrl+'/user/problem').toPromise().then(res=>{
      return res;
    })
  }
  //获取用户的密保问题以及答案
  getProblemByUser(userGuid):Promise<any>{
    return this.http.get(this.serveUrl+'/user/info/problem?userGuid='+userGuid).toPromise().then(res=>{
      return res;
    })
  }
  //修改密保问题以及答案
  updateProblem(data):Promise<any>{
    return this.http.put(this.serveUrl+'/user/putSecurity',data).toPromise().then(res=>{
      return res;
    })
  }
  //用户Guid和密码验证
  passwordOrUserId(userGuid,password):Promise<any>{
    return this.http.get(this.serveUrl+'/user/info/pass?userGuid='+userGuid+'&password='+password).toPromise().then(res=>{
       return res;
    })
  }
  //修改密码
  updatePassWord(data):Promise<any>{
    return this.http.put(this.serveUrl+'/user/putPassWord',data).toPromise().then(res=>{
      return res;
    })
  }

}



